package com.hy.mydesktop.server.rpc;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.ModelData;
import com.hy.mydesktop.shared.rpc.meta.GxtToSeamServiceParameter;

public class T {

	/**
	 * <ul>
	 * <li>方法含义：</li>
	 * <li>方法作者：花宏宇</li>
	 * <li>编写日期：2010-9-28；时间：下午下午03:25:08</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 * @param args
	 */
	public static void main(String[] args) {

		/*String  str = "xx";
		
		T t = new T();
		Object object =t.invokeService("com.test.server.business.PersonService", "listPerson", null);
		List<BaseModel> list = (List<BaseModel>)object;
		for (BaseModel baseModel : list) {
			System.out.println(baseModel);
		}*/
		
		GxtToSeamServiceParameter gxtToSeamServiceParameter=
			new GxtToSeamServiceParameter();
		ModelData[] modelDatas=new BaseModel[5];
		modelDatas[0]=new BaseModel();
		System.err.println(modelDatas.length);
		gxtToSeamServiceParameter.getMethodArguments();
	}

	
	public Object invokeService(String serviceClassName, String serviceMethodName, 
			Object[] parameterList)  {
		
//gxtComponentMetaModel.get(property, valueWhenNull);
		
		//反射，解析field，查看gxtComponentMetaModel中是否存在当前属性，如果存在，则switch|case赋值
		Class c = null;
		Method method = null;
		Class[] argclass = null;
		try {
			c = Class.forName(serviceClassName);
			Object object =c.newInstance();
			if (parameterList == null) {
				
			} else {
				argclass =new Class[parameterList.length];
				for(int i=0,j=argclass.length;i<j;i++){
		            argclass[i]=parameterList[i].getClass();
		        }
			}
			
		        
		    method=c.getMethod(serviceMethodName, argclass);
		    return method.invoke(object	, parameterList);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
			return null;
		
		
		
		
		
	}
}
